package com.gksc.video.config;

import com.gksc.video.constant.CacheConstant;
import com.gksc.video.manager.BasePushThread;
import com.gksc.video.schedule.SystemCheckSelfJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;

/**
 * @className: StopHandler
 * @description: 服务结束处理类
 * @author: Liao.yx
 * @email: 1229053515@qq.com
 * @create: 2021年05月14日 16时39分
 * @copyRight: 2020 liaoyongxiang All rights reserved.
 **/
@Slf4j
@Component
public class StopHandler {
    @Qualifier("taskExecutor")
    @Autowired
    private ThreadPoolTaskExecutor taskExecutor;

    @PreDestroy
    public void destroy() {
        log.info("服务结束，开始释放空间...");
        log.info("停止定时任务");
        for (BasePushThread task : CacheConstant.JOBMAP.values()) {
            task.cancel();
        }
        SystemCheckSelfJob.systemCheckSelfJob.cancel();
        log.info("清除线程池");
    }
}
